class Rational(n: Int, d: Int)
{
    require(d != 0)

    private val g = gcd(n, d)
    val numer = n / g
    val denom = d / g

    override def toString = numer + "/" + denom
    private def gcd(a: Int, b: Int): Int = {
      if ( b == 0 ) a else gcd(b, a % b)
    }
}
